BATCH

            Normally the JDBC statements are send to the Database individually . to send multiple statements at one time we will use add batch method to append statement to the original statement call the the executeBatch method to submit entire statement.

Program on Batch

import java.sql.*;
public class Sample
{
public static void main(String args[])
{
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vision","scott","tiger");
Statement st=con.createStatement();
st.addBatch(“insert into abc values(100,’prasad’,5600)”);                      
st.addBatch(“insert into abc values(200,’renu’,6500)”);
st.addBatch(“insert into abc values(300,’vamsi’,3500)”);
st.addBatch(“update abc set sal=sal+1000 where eno=100”);
int r[]=st.executeBatch();
System.out.println(r.length+"Rows Inserted");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}